# load data
datos <- read.table("ping_comparativo.out", header=T) # host ping hr fibra lping
graf <- "ping_comparativo.png"

hosts = datos$host
fibra = datos$fibra
dom   = datos$dom
lun   = datos$lun
mar   = datos$mar

len = length(hosts)

print(datos)

# plot
png(filename=graf, width=1024, height=768, bg="white")

par(mar=c(10,5,5,2))  # manipulate margins (bottom,left,top,right)

g_range <- range(0, dom, lun, mar, fibra)  # Calculate range from 0 to max value

# Graph using y-axis that g_ranges 
# Turn off axes and annotations (axis labels) so we can specify them ourself
plot(rep(1000, len), type="l", col="grey80", ylim=g_range, axes=FALSE, ann=FALSE)

# Make y-axis with horizontal labels that display ticks at 
# every 100 marks. 100*0:g_range[2] is equivalent to c(0,100,200,...,1000).
axis(2, las=1, at=100*0:g_range[2])

# Make x-axis tick marks without labels
axis(1, lab=F, at=1:len)

# Plot x-axis labels at default tick marks with labels at 45 degree angle
text(1:len, par("usr")[3] - 50, srt=45, adj=1, labels=hosts, xpd=T, cex=0.8)

box() # box around plot

lines(dom,  type="b", pch=21, lty=1, col="blue")        # plot dom
lines(lun,  type="b", pch=21, lty=1, col="forestgreen") # plot lun
lines(mar,  type="b", pch=21, lty=1, col="magenta")     # plot mar
lines(fibra, type="b", pch=22, lty=1, col="red")        # plot fibras

title(main="Mediciones de Ping a Universidades \n
            Promedio de RTT sobre 100 repeticiones - Comparativo",
      xlab="", ylab="Time (ms)")      # titles

# legend: x-pos, y-pos, names, ...
legend(0.65, 1330, c("TIMEOUT","Domingo","Lunes","Martes","Fibra"), cex=0.8,
        col=c("grey80", "blue","forestgreen","magenta","red"),
        pch=c(45,21,22,20), lty=c(1,0,0,0))

dev.off()
